<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.11.2.js"></script>
</head>
<body>
	<form action="${pageContext.request.contextPath }/animal/animal_update" method="post">
	<div>
		动物编号:<input name="animal.aid" value="${a.aid}"/><br><br>
		动物名称:<input name="animal.aname" value="${a.aname}"/><br><br>
			<input type="hidden" name="animal.imgPath" value="${a.imgPath }">		
		图片:<img style="width:100px;height:100px" src="/pic/${a.imgPath}"/><input type="file" name="imgUpload"/><br><br>
		日期:<input name="animal.createDate" value='<fmt:formatDate value="${a.createDate}" pattern="yyyy-MM-dd" />' /><br><br>
		<%-- 动物种类:<input name="animal.aid" value="${a.category.cname}"/><br><br>
		分布范围:<input name="animal.aid" value="${a.distribution.dname}"/><br><br> --%>
		动物种类:<select name="animal.category.cid" id="cid" >
			<option value="0">==请选择==</option>
		</select>
		<br><br>		
		<!-- 分布范围:<select name="animal.distribution.did" id="did" >
			<option value="0">==请选择==</option>
		</select>
		<br><br> -->
		<input type="submit" value="修改">
	</div>
	</form>
	<script>
	$(function(){
		$.post(
				"{pageContext.request.contextPath}/animal/animal_showCategory",
				//加载category json数组
				function(data){
					console.log(data);
					var sel = $("#cid");
					var cate = '${a.category.cid}';
					console.log(cate);
					for(var j in data){
						if(data[j].cid == cate){
							sel.append("<option value='"+data[j].cid+"'selected >=="+data[j].cname+"==</option>");

						}else{
							sel.append("<option value='"+data[j].cid+"'>=="+data[j].cname+"==</option>");
						}
						
					} 
				},
				"json"
			);
			$.post(
					"{pageContext.request.contextPath}/animal/animal_showDistribution",
					//加载Distribution json数组
					function(data){
						console.log(data)
						var sel = $("#did");
						var dis = '${a.distribution.did}';
						console.log(dis);
						for(var i in data){
							if(data[i] == dis){
								sel.append("<option value='"+data[i]+"' selected >=="+data[i].dname+"==</option>");

							}else{
								sel.append("<option value='"+data[i]+"'>=="+data[i].dname+"==</option>");

							}
						}
					},
					"json"
				); 
		
	})
	</script>
</body>
</html>